package demo.kafka;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.annotation.KafkaListeners;
import org.springframework.stereotype.Service;

/**
 * @description description
 * 
 * @author zhouxinghuai
 * @date 2018-10-16
 */
@Service
public class ConsumerListenerService2 {

    @KafkaListener(topics = {"test", "test1"}, containerFactory = "kafkaListenerContainerFactory")
    void consumer(ConsumerRecord<String, String> consumerRecord){
        System.err.println("Handle from ConsumerListenerService2#consumer");
        //根据不同topic，消费
        if ("test".equals(consumerRecord.topic())) {
            //topic:test
            System.err.println("topic:test -> " + consumerRecord.value());
        } else if ("test1".equals(consumerRecord.topic())) {
            //topic:test1
            System.err.println("topic:test1 -> " + consumerRecord.value());
        }
    }

    @KafkaListener(topics = {"test2"}, containerFactory = "kafkaListenerContainerFactory")
    void consumer2(ConsumerRecord<String, String> consumerRecord){
        System.err.println("Handle from ConsumerListenerService2#consumer2");
        //根据不同topic，消费
        System.err.println("topic:test2 -> " + consumerRecord.value());
    }
    
}
